<?php
namespace Model;
/**
 * klasa modeli kategorii i ich drzewa
 */
class Category extends \Model {
	private $root;
	public function __construct ($data) {
		$log = new \Log('Model\Category::__construct');
		$log->add(print_r($data, true));
		$this->root  = new CategoryNode(self::$database->categories->findOne(), $data['category']);
		$this->data = $this->root;
	}
}
class CategoryNode extends \Model {
	private $name;
	private $alias;
	private $subcategories;
	private $path;
	public function __construct ($subTree, $path = false) {
		self::init();
		$log = new \Log('Model\CategoryNode::__construct');
		$log->add(print_r($subTree, true));
		if(array_key_exists('subcategories', $subTree)) {
			for($i=0, $l=count($subTree['subcategories']); $i<$l; $i++) {
				$this->subcategories[] = new CategoryNode($subTree['subcategories'][$i]);
			}
		} else {
			$this->subcategories = false;
		}
		$this->name = $subTree['name'];
		$this->alias = $subTree['alias'];
		$this->path = $path;
	}
	public function getName () {
		return $this->name;
	}
	public function getAlias () {
		return $this->alias;
	}
	public function getSubcategories () {
		return $this->subcategories;
	}
	public function getPath () {
		return $this->path;
	}
}
?>